package com.mine.dubbo.netty.server;

import com.mine.dubbo.netty.model.Request;
import com.mine.dubbo.netty.model.Response;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class ServerHandler extends ChannelInboundHandlerAdapter {
    /**
     * 客户端主动连接时回调
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        System.out.println("channelActive");
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        log.info("接收消息成功");
        Request request = (Request) msg;
        Response response = new Response(request, "dkjfhasdkjfga");
        ctx.writeAndFlush(response);
    }

    /**
     * 客户端主动关闭连接时回调
     */
    @Override
    public void channelInactive(ChannelHandlerContext ctx) {
        System.out.println("channelInactive");
    }
}
